package com.robot.member.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.robot.member.pojo.CartDetails;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * details数据访问接口
 *
 * @author wuyunbin
 */
public interface CartDetailsDao extends JpaRepository<CartDetails, String>, JpaSpecificationExecutor<CartDetails> {
    /**
     * 通过cartId和goodsId查找CartDetails
     *
     * @param cartId
     * @param goodsId
     * @return
     */
    public CartDetails findByCartIdAndGoodsIdAndDeletedAtIsNull(String cartId, String goodsId);

    /**
     * 通过cartId查找CartDetails
     *
     * @param cartId
     * @return
     */
    public List<CartDetails> findAllByCartIdAndDeletedAtIsNull(String cartId);

    /**
     * 通过cartId删除CartDetails
     *
     * @param cartId
     */
    @Modifying
    public void deleteAllByCartId(String cartId);

    /**
     * 通过cartId和goodsId删除CartDetails
     *
     * @param cartId
     * @param goodsId
     */
    @Modifying
    @Query(value = "delete from member.cart_details where member.cart_details.cart_id=? and member.cart_details.goods_id=?", nativeQuery = true)
    public void deleteByCartIdAndGoodsId(String cartId, String goodsId);
}
